<?php
ob_start();

// basepath konstante definieren
if (!defined('BASEPATH')) {
	define('BASEPATH', dirname(__FILE__).DIRECTORY_SEPARATOR);
}


require_once BASEPATH.'lib/Core.class.php';
require_once BASEPATH.'lib/smarty/Smarty.class.php';

// session initialisieren
$session = Core::getSession();
$session->initialize(15);

// smarty initialisieren
$smarty = new Smarty();
$smarty->setCacheDir(BASEPATH.'cache');
$smarty->setCompileDir(BASEPATH.'cache');
$smarty->setTemplateDir(BASEPATH.'templates');

if (Core::getSession()->isSessionRegistered()) {
	if (Core::getSession()->isSessionExpired()) {
		Core::getSession()->destroySession();
	} else {
		Core::getSession()->renewSession();
	}
}

// header anzeigen
$smarty->display("templates/header.tpl");

if(isset($_SESSION['reg_user'])){
	$admin = $_SESSION['admin'];
	$name = $_SESSION['reg_user'];
}

// Sollte der Benutzer eine Session haben
if (isset($name) && !empty($name)) {
	$smarty->assign('admin', $admin);
	$smarty->assign('name', $name);
	if ($admin == 1) {
		$smarty->display('adminMenu.tpl');
	} else {
		$smarty->display('menu.tpl');
	}
}
if (isset($_GET['page'])) {
	switch ($_GET["page"]) {
		
		case "reg":
			include_once BASEPATH.'content/reg.php';
			break;

		case "registrieren":
			include_once BASEPATH.'content/registrieren.php';
			break;

		case "logtest":
			include_once BASEPATH.'content/logtest.php';
			break;

		case "logged":
			include_once BASEPATH.'content/logged.php';
			break;
			
		case "profil":
			include_once BASEPATH.'content/profil.php';
			break;
			
		case "terminBearbeiten":
			include_once BASEPATH.'content/terminBearbeiten.php';
			break;
			
		case "password":
			include_once BASEPATH.'content/password.php';
			break;

		case "fetch":
			echo "fetch!!";
			include_once BASEPATH.'content/fetch.php';
			exit;

		case "logout":
			include_once BASEPATH.'content/logout.php';
			break;

		case "nTermin":
			include_once BASEPATH.'content/nTermin.php';
			break;
				
		case "personFrei":
			include_once BASEPATH.'content/personFrei.php';
			break;
				
		case "terminFrei":
			include_once BASEPATH.'content/terminFrei.php';
			break;

		default:
			include_once BASEPATH.'content/404.php';
			break;
	}

} else {
	if(!isset($_SESSION['reg_user'])){
		include_once BASEPATH.'content/login.php';
	}else{
		include_once BASEPATH.'content/logged.php';
	}
}

// zum schluss footer anzeigen
$smarty->display("templates/footer.tpl");

ob_end_flush();
?>
